package Code.Objects.Characters.Player.Weapons.Ranged.AmmoBased.SingleFire.Shotgun;

import org.jrabbit.base.managers.window.WindowManager;
import org.jrabbit.standard.game.graphics.skins.image.ImageSkin;
import org.jrabbit.standard.game.objects.text.TextSprite;

import Code.Objects.Characters.Player.Player;
import Code.Objects.Characters.Player.Skins.Weapons.PlayerShotgunSkin;
import Code.Objects.Characters.Player.Weapons.WeaponSoundPlayer;
import Code.Objects.Characters.Player.Weapons.Ranged.AmmoBased.SingleFire.PlayerSingleFireWeapon;
import Code.Objects.Effects.Projectiles.Player.Short.ShotgunBullet;
import Code.Objects.Effects.Visual.GunfireBursts.Large.LargeGunfireBurst1;

public class PlayerShotgun extends PlayerSingleFireWeapon
{
	private TextSprite readout;
	
	public PlayerShotgun(Player p)
	{
		super(new PlayerShotgunSkin(), p);
		offset = 25;
		shotInterval = 6000;
		cameraModePreference = 1;
		reloadDuration = 3800;
		ammoPerClip = 6;
		maxClips = 5;
		
		name = "Shotgun";
		description = "A powerful, wide-shot weapon designed for crowd control and close-range combat.";
		
		fillAmmo();

		readout =  new TextSprite("Ammo In Clip: " + ammoInClip + "\nSpare Ammo: " + spareAmmo);
		readout.useScreenCoords(true);
		readout.location().set(WindowManager.getDisplayWidth() - 200, 14);
		icon = new ImageSkin("Resources/Images/GUI/Game/Weapon Selection/Icons/Shotgun.png");
	}
	
	public void outOfAmmo()
	{
		WeaponSoundPlayer.playShotgunSound(1f, 2);
	}
	
	public void beginReload()
	{
		reloadTimer = 0;
		reloading = true;
	}
	
	public void finishReload()
	{
		if(ammoInClip == ammoPerClip || spareAmmo == 0)
		{
			reloading = false;
			animation.setCycle(0);
		}
		else
		{
			ammoInClip++;
			spareAmmo--;
			animation.setCycle(1);
			WeaponSoundPlayer.playShotgunSound(0.7f, 1);
		}
	}
	
	public void fire()
	{
		WeaponSoundPlayer.playShotgunSound(1f, 0);
		for(int i = 0; i < 15; i++)
		{
			getOwner().getWorld().addEffect(new ShotgunBullet(location, rotation.angle(), 50), "Effects B");
		}
		LargeGunfireBurst1 burst = new LargeGunfireBurst1(this, 50, owner.getWorld());
		getOwner().getWorld().addRenderable(burst, "Effects B");
		getOwner().getWorld().addUpdateable(burst);
	}
	
	public void renderGUI()
	{
		super.renderGUI();
		readout.setText("Ammo In Clip: " + ammoInClip + "\nSpare Ammo: " + spareAmmo);
		readout.render();
	}
}